package com.zmwx.auth.domain.service.impl;

import com.alibaba.fastjson.JSON;
import com.zmwx.auth.common.enums.IsDeletedFlagEnum;
import com.zmwx.auth.domain.convert.AuthRoleBOToConverter;
import com.zmwx.auth.domain.entityDO.AuthRoleBO;
import com.zmwx.auth.domain.service.AuthRoleDomainService;
import com.zmwx.auth.infra.basic.entity.AuthRole;
import com.zmwx.auth.infra.basic.service.AuthRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {
    @Resource AuthRoleService authRoleService;
    @Override
    public boolean addRole(AuthRoleBO authRoleBO) {
        AuthRole authRole=AuthRoleBOToConverter.INSTANCE.convertBOToEntity(authRoleBO);
        if (log.isInfoEnabled()){
            log.info("addRole:{}", JSON.toJSONString(authRole));
        }
        int insert = authRoleService.insert(authRole);
        return insert>0;
    }

    @Override
    public boolean updateRole(AuthRoleBO authRoleBO) {
        AuthRole authRole=AuthRoleBOToConverter.INSTANCE.convertBOToEntity(authRoleBO);
        Integer count = authRoleService.update(authRole);
        return false;
    }
    @Override
    public boolean deleteRole(AuthRoleBO authRoleBO) {
        AuthRole authRole=AuthRoleBOToConverter.INSTANCE.convertBOToEntity(authRoleBO);
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        Integer count = authRoleService.update(authRole);
        //TODO 删除角色时，需要删除角色对应的权限
        return count>0;
    }
}
